package com.tarena.lbs.basic.web.repository;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.base.protocol.pager.BasePageList;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.mapper.UserGroupMapper;
import com.tarena.lbs.basic.web.mapper.UserMapper;
import com.tarena.lbs.common.basic.converter.UserGroupConverter;
import com.tarena.lbs.pojo.basic.bo.UserBO;
import com.tarena.lbs.pojo.basic.bo.UserGroupBO;
import com.tarena.lbs.pojo.basic.dos.UserDO;
import com.tarena.lbs.pojo.basic.dos.UserGroupDO;
import com.tarena.lbs.pojo.basic.dos.UserTagsDO;
import com.tarena.lbs.pojo.basic.query.UserGroupQuery;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Repository
public class UserRepository {
    @Autowired
    private UserMapper userMapper;
    public void saveUser(UserBO userBO) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userBO,userDO);
        userMapper.saveUser(userDO);
    }

    public UserBO getUserByPhone(String phone) {
        UserDO userDO=userMapper.selectUserByPhone(phone);
        if (userDO!=null){
            UserBO userBO=new UserBO();
            BeanUtils.copyProperties(userDO,userBO);
            return userBO;
        }
        return null;
    }

    public UserBO selectById(Integer userId) {
        UserDO userDO = userMapper.selectUserById(userId);
        if (userDO!=null){
            UserBO userBO = new UserBO();
            BeanUtils.copyProperties(userDO,userBO);
            return userBO;
        }
        return null;
    }


    public void bindUsertags(List<UserTagsDO> userTagsDOS) {
        userMapper.bindUsertags(userTagsDOS);
    }

    public void deleteUserTagsById(Integer userId) {
        userMapper.deleteUserTagsById(userId);
    }

    public void updateUserStatus(Integer userId, int i) {
        UserDO userDO = new UserDO();
        userDO.setId(userId);
        userDO.setStatus(i);
        userMapper.updateUserStatus(userDO);
    }

}
